// 布尔类型
let bool: boolean = false;
bool = true

// 数值类型
let num: number = 123;
num = 0b110101001
num = 0o1234567
num = 0x123890abcdef

// 字符串类型
let str: string = "default"
str = "string"

// 数组类型
let arr: number[]
let arr2: (string | number)[]
// tslint:disable-next-line: array-type
let arr3: Array<number> // 推荐上面的写法
// tslint:disable-next-line: array-type
let arr4: Array<string | number> // 推荐上面的写法
arr = [1, 2]
arr2 = [1, "2"]
arr3 = [1, 2]
arr4 = [1, "2"]

// 元组类型(长度与类型必须与定义一致)
let tuple: [string, number, boolean]
tuple = ["1", 1, true]

// 枚举类型
enum Roles {
    SUPER_ADMIN, // value 0
    ADMIN = 4,
    USER // value 5
}

// any 类型
// tslint:disable-next-line: prefer-const
let value: any
let anyArr: any[]
anyArr = [1, "2", false]

// void 类型
let v: void
v = undefined
const voidTest = (test: string): void => {
    console.log(test);
}
function voidTest2(test: string): void {
    console.log(test);
}

// null 和 undefined
const nullVal: null = null, undefinedVal: undefined = undefined;

// never 类型,永远不存在返回的类型
const errorFunc = (message: string): never => {
    throw new Error(message)
}
const infiniteFunc = (): never => {
    while (true) {
        console.log("while");
    }
}

// object 类型
function getObj(obj: object): void {
    console.log(obj);
}

// 类型断言 eg:<string>,(target as string)
const getLength = (target: string | number): number => {
    // tslint:disable-next-line: no-angle-bracket-type-assertion
    if ((<string>target).length || (target as string).length === 0) {
        // tslint:disable-next-line: no-angle-bracket-type-assertion
        return (<string>target).length
    } else {
        return target.toString().length
    }
}

export default {
    a: 1
}
